<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<jsp:directive.page import="cn.antia.cwin.window.MultiWindow"/>
<jsp:directive.page import="java.util.HashMap"/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="/WEB-INF/tld/FCKeditor.tld" prefix="FCK" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!--取出window对象-->
<c:set var="window" value="${sessionScope[requestScope.jwas_single_window_id]}"/>
<c:set value="${sessionScope.jwas_multi_window_id}" var="multiWindow"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>${multiWindow.desc}</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="StyleSheet" href="cep/css/cep.css" type="text/css"/>
  </head>
  <script type="text/javascript" src="cep/js/mootools/mootools_hash.js"></script>
  <script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
  <script type="text/javascript" src="cep/js/validation/validation.js"></script>
  <script type="text/javascript" src="cep/js/validation/form_auto_validation.js"></script>
  <script type="text/javascript" src="cep/js/sort.js"></script>
  <script type="text/javascript">
  	var pri_sec = new Hash();
  	<%
  	MultiWindow window = (MultiWindow)session.getAttribute("jwas_multi_window_id");
	HashMap relations = window.getRelations();
  	Object[] keys = relations.keySet().toArray();
  	String value,printStr;
  	for(int i = 0;i<keys.length;i++){
  		value = (String)relations.get(keys[i]);
  		printStr = "pri_sec.set('" + keys[i] + "','" +  value + "')";
  		out.print(printStr);
  	}
  	%>
  	
  	function reloadSecondary(){
  		var relationKeys = pri_sec.keys();
  		var url = "1";
  		for(var i = 0;i<relationKeys.length;i++){
  			var akey = relationKeys[i];
  			var priValue = eval("easymana_form." + akey + ".value");
  			var secField = pri_sec.get(akey);
  			if(url == "1") url = secField + "=" + priValue;
  			else url = url + "&" + secField + "=" + priValue;
  		}
  		url = "window.was?id=${multiWindow.secondary}&" + url;
  		var frm = $("iframe_secondary");
  		frm.src=url;
  	}
  </script>
  <body>
    <b>${window.desc }</b><span style="padding-left:50px;color: #700700" id="easy_mana_err_span">${message }<font color="red"> ${err_msg}</font></span>
    <c:if test="${empty window}" var ="noWindow">
    <!--如果没有，取得这个窗体的属性 -->
	   not window
    </c:if><c:if test = "${!noWindow}"><c:set var = "rowNum" value = "${window.dispCol}"/><!-- 显示表属性，并且以表单形式呈现 -->
    <form name="form_jump_page" method="${window.method}" action="${window.action}">
    	<INPUT type="hidden" name="action" value="topage" />
    	<INPUT type="hidden" name="toPage" value="" />
    </form>
    <FORM name="${window.formName}" method= "${window.method}" action="${window.action}">
    	<INPUT type="hidden" name="jwas_single_window_id" value="${requestScope.jwas_single_window_id}" />
	    <TABLE width="100%">
	    <c:set var="posi" value="${-1}"></c:set>
    	<c:forEach var="fele"  items="${window.fields}" varStatus="status">
    	<c:set var="fht" value="${fele.htmlType}">
    	</c:set><c:set var="fn" value="${fele.fieldName}"></c:set>
    		<c:if test="${fht != 'hidden'}" var = "notHidden" scope="page"><c:set var="posi" value="${posi + 1}"></c:set></c:if>
    		<c:if test="${notHidden && posi % rowNum == 0}"><tr></c:if>
    		<c:if test="${!notHidden}"><input type = "${fht}" name="${fn}" value="" size="${fele.size}" ${fele.readonly ? 'readonly=readonly' : '' }/></c:if>
    		<c:if test="${notHidden && fht != 'select' && fht != 'textarea' && fht != 'fckeditor'}">
	    		<td>${fele.dispText}</td><TD><input type = '${fht}' name="${fn}" value="" size="${fele.size}" ${fele.readonly ? 'readonly=readonly' : '' } limit="${fele.limits}" msg="${fele.comment}"></TD>
    		</c:if>
	    		<c:if test = "${fht == 'select'}">
	    			<td>${fele.dispText}</td>
	    			<td><SELECT name="${fn}" value="" <c:if test="${fele.onchange != null}">onchange = "${fele.onchange}"</c:if>  limit="${fele.limits}" msg="${fele.comment}" <c:if test="${fele.readonly}"> readonly="readonly"</c:if>>
	    				<option value="">未选择</option>
	    				<c:forEach var="option" items="${fele.dispList}"><option value="${option.key}">${option.value}</option></c:forEach>
	    			</SELECT></td>
	    		</c:if>
	    		<c:if test = "${fht == 'textarea'}">
	    			<td>${fele.dispText}</td><td><textarea name="${fn}" rows="${fele.rows}" cols="${fele.cols}"  limit="${fele.limits}" msg="${fele.comment}"></textarea></td>
	    		</c:if>
	    		<c:if test = "${fht == 'fckeditor'}">
	    			<c:if test="${posi%rowNum == 0}"><td></td></tr><tr>
	    			</c:if>
	    			<c:if test="${posi%rowNum == 1}"></tr>
		    			<tr>
	    			</c:if>
	    			<td>${fele.dispText}</td>
	    			<td colspan="3">
	    			<textarea id="${fn}" name="${fn}" cols="${fele.cols}" rows="${fele.rows}"></textarea>
						<script type="text/javascript">
						 var oFCKeditor = new FCKeditor('${fn}') ;
						 oFCKeditor.BasePath = 'FCKeditor/';
						 oFCKeditor.ToolbarSet = "Basic" ;
						 oFCKeditor.Height = ${fele.rows};
						 oFCKeditor.Width = ${fele.cols};
						 //oFCKeditor.ToolbarSet = "Gk" ; 
						 oFCKeditor.ReplaceTextarea();
						</script>
	    			</td>
	    			<c:if test="${posi % rowNum == 0}">
	    				</tr><tr>
	    			</c:if>
	    		</c:if>
	    	<c:if test="${notHidden && posi % rowNum == 1}">
    			</tr>
    		</c:if>
    	</c:forEach>
	<!-- 操作按纽 -->
	<tr>
    <td colspan="4">
    	<c:if test="${window.methods != null}">
    		<c:forEach items="${window.methods}" var="method">
    			<c:if test="${method == 'add'}">
    				<input type="button" onclick="addRecord();" value="新增" id="but_inse"/>
    			</c:if><c:if test="${method == 'query'}">
    				<input type="button" onclick="operateForm('query');" value="查询" id="but_quer"/>
    			</c:if><c:if test="${method == 'update'}">
    				<input type="button" onclick="operateForm('update');" value="保存" id="but_upda"/>
    			</c:if><c:if test="${method == 'delete'}">
    				<input type="button" onclick="operateForm('delete');" value="删除" id="but_dele"/>
    			</c:if>
    		</c:forEach>
    	</c:if>
    </td>
  </tr>
	    </TABLE>
    </FORM>
    </c:if>
    <hr>
    <!-- 显示结果集 --><!--取出Table对象-->
    <c:set value="window_${window.id}" var="tableSessionName"></c:set>
    <c:set var="dtable" value="${requestScope[tableSessionName]}"/>
    <c:set var="noData" value="${dtable == null || dtable.rows == null}"/>
    <c:if test="${!noData}">
    <span class="page_desc">Page:${dtable.currentPage}/${dtable.pageCount} &nbsp;&nbsp;${fn:length(dtable.rows)} resords. Total record:${dtable.recordCount}</span>
    <!-- 显示表头 --><!-- 显示表体 -->
    <div class="single_grid_window">
    <c:set var="index_start" value="${(dtable.currentPage - 1) * dtable.pageSize}"></c:set>
    <TABLE id = "${dtable.gridId}" cellspacing="1" cellpadding="3" style="background-color: #000000;">
    	<tr>
    		<td onclick="sort_this_table(this)" class="grid_th">序号</td>
	    	<c:forEach var="th" items="${dtable.th}">
	    		<td id = "${th.id}" onclick="sort_this_table(this)" class="grid_th">${th.value}</td>
	    	</c:forEach>
    	</tr>
    	<c:forEach var="row" items="${dtable.rows}" varStatus="i">
    		<tr onclick="copy(this,false)" onmousemove="mOvr(this)" onmouseout="mOut(this)">
    		<td>${index_start + i.index + 1 }</td>
    		<c:forEach var="element" items="${row}" varStatus="j">
    			<c:set value="${element.value}" var="en1"></c:set>
    			<c:if test="${en1 != null && (en1 == 'hiddendiv' || en1 == 'hidden' || en1 == 'pop')}" var="hid">
    				<c:if test="${en1 == 'hiddendiv'}">
    					<TD><div id="div_${i.index}_${j.index}'" style="display:none">${element.value}</div></TD>
    				</c:if>
    				<c:if test="${en1 == 'hidden'}">
    					<TD>b<pre style="display:none">${element.value}</pre></TD>
    				</c:if>
    				<c:if test="${en1 == 'pop'}">
    					<TD onmouseover="dispTd('pop_${i.index}_${j.index}')" onmouseout="hideTd('pop_${i.index}_${j.index}')"><div id="pop_${i.index}_${j.index}" style="display:none">${element.value}</div>...</TD>
    				</c:if>
    			</c:if>
    			<c:if test="${!hid}">
    				<TD>${element.value}</TD>
    			</c:if>
    		</c:forEach>
    		</tr>
    	</c:forEach>
    </TABLE>
    <DIV class="page_index">
      <c:set value="${dtable.currentPage}" var="midder"/>
      <c:if test="${midder - 6 < 0}" var="x6">
      	<c:set value="${1}" var="start"></c:set>
      	<c:if test="${dtable.pageCount > 10}" var="last">
      		<c:set value="${10}" var="end"></c:set>
      	</c:if>
      	<c:if test="${!last}">
      	<c:set value="${dtable.pageCount}" var="end"></c:set>
      	</c:if>
      </c:if>
     <c:if test="${!x6}">
      	<c:if test="${midder + 5 >= dtable.pageCount}">
      		<c:set value="${dtable.pageCount}" var="end"></c:set>
      	</c:if>
      	<c:if test="${midder + 5 < dtable.pageCount}" var="last">
      		<c:set value="${midder + 5}" var="end"></c:set>
      	</c:if>
      	<c:if test="${end - 10 > 0}" var="first">
      		<c:set value="${end - 10}" var="start"></c:set>
      	</c:if>
      	<c:if test="${!first}">
      		<c:set value="${1}" var="start"></c:set>
      	</c:if>
      </c:if>
      GO PAGE:<c:if test="${first}"><A href="javaScript:goPage(${1});">First</A></c:if>
      <c:forEach begin="${start}" end="${end}" var="i">
      	<c:if test="${i == dtable.currentPage}" var="test"><A href="javaScript:goPage(${i});"><span class="page_index_current">&nbsp;${i}</span></A></c:if>
      	<c:if test="${!test}"><A href="javaScript:goPage(${i});">&nbsp;${i}</A></c:if>
      </c:forEach>
      <c:if test="${last}"><A href="javaScript:goPage(${dtable.pageCount});">&nbsp;Last</A></c:if>
      </DIV>
    </div>
    </c:if>
    <div id="display" class="display"></div>
    <script type="text/javascript" src="cep/js/window.js"></script>
	<script type="text/javascript" src="cep/js/window_copy_pri.js"></script>
	<script language="javascript">
		setTableId("t_${table}");
		setFormName("${window.formName}");
	</script>
	<br/><br>
	<iframe src="window.was?id=${multiWindow.secondary}" id="iframe_secondary" name="secondary" frameborder="0" width="100%" height="570"></iframe>
  </body>
</html>